%% Author: Dmitriid
%% Created: 20.09.2006
%% Description: TODO: Add desciption to orcas_soap_client
-module(orcas_soap_client).

%%
%% Include files
%%

%%
%% Exported Functions
%%
-export([request/1]).
 
%%
%% API Functions
%%

%%
%% TODO: Add description of request/function_arity 
%%
request(Req) ->
    ibrowse:start_link(),
    {ok, Status, ResponseHeaders, ResponseBody} = 
    ibrowse:send_req("http://rsdn.ru/ws/JanusAT.asmx", [{"SOAPAction", "\"http://rsdn.ru/Janus/" ++ element(1, Req) ++ "\""}, {"Content-Type", "text/xml; charset=utf-8"}], post, getSOAPMessage(Req))
	,
    ResponseBody
    .

%%
%% Local Functions
%%

getSOAPMessage(Req) ->
	xmlProlog() ++ 
    envelope(Req).

xmlProlog() ->
	"<?xml version=\"1.0\" encoding=\"utf-8\"?>".

envelope(Req) ->
    orcas_soap_encoder:encode({"soap:Envelope", {attributes, [{"xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"},
                                                              {"xmlns:xsd", "http://www.w3.org/2001/XMLSchema"},
                                                              {"xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/"}]},
                               {"soap:Body", Req}}).    